import base64
import json
import os.path
import requests
from lxml import etree
from bs4 import BeautifulSoup

url = 'https://www.rzjqgyr.com/archives/201028/'
header = {
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
'referer':'https://www.rzjqgyr.com/archives/201028/'
}


session = requests.session()
response = session.get(url,headers=header)
response.encoding = 'utf8'

if not os.path.exists('LINN图片集'):
    os.mkdir('LINN图片集')

tree = etree.HTML(response.text)



title = tree.xpath('//*[@id="post"]/article/div[5]/p[5]/img/@data-xkrkllgl')[0]
print('1')
base64str = session.get(title,headers=header).text

#print('获取到的是:\n' + base64str)

# 去除前缀（如有）
if base64str.startswith('data:image'):
    base64_data = base64str.split(',')[1]
else:
    base64_data = base64str
#print('base64:' + base64_data)
# 解码并保存为图片
img_data = base64.b64decode(str(base64_data))
with open('./LINN图片集/1.png', 'wb') as f:
    f.write(img_data)
print('图片已保存')